package com.ruoyi.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.contract.domain.ContractAppendices;
import com.ruoyi.contract.service.IContractAppendicesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同附件Controller
 * 
 * @author ruoyi
 * @date 2024-10-18
 */
@RestController
@RequestMapping("/contract/ContractAppendices")
public class ContractAppendicesController extends BaseController
{
    @Autowired
    private IContractAppendicesService contractAppendicesService;

    /**
     * 查询合同附件列表
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractAppendices:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractAppendices contractAppendices)
    {
        startPage();
        List<ContractAppendices> list = contractAppendicesService.selectContractAppendicesList(contractAppendices);
        return getDataTable(list);
    }

    /**
     * 导出合同附件列表
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractAppendices:export')")
    @Log(title = "合同附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractAppendices contractAppendices)
    {
        List<ContractAppendices> list = contractAppendicesService.selectContractAppendicesList(contractAppendices);
        ExcelUtil<ContractAppendices> util = new ExcelUtil<ContractAppendices>(ContractAppendices.class);
        util.exportExcel(response, list, "合同附件数据");
    }

    /**
     * 获取合同附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractAppendices:query')")
    @GetMapping(value = "/{contractAppendicesId}")
    public AjaxResult getInfo(@PathVariable("contractAppendicesId") Long contractAppendicesId)
    {
        return success(contractAppendicesService.selectContractAppendicesByContractAppendicesId(contractAppendicesId));
    }

    /**
     * 新增合同附件
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractAppendices:add')")
    @Log(title = "合同附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractAppendices contractAppendices)
    {
        return toAjax(contractAppendicesService.insertContractAppendices(contractAppendices));
    }

    /**
     * 修改合同附件
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractAppendices:edit')")
    @Log(title = "合同附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractAppendices contractAppendices)
    {
        return toAjax(contractAppendicesService.updateContractAppendices(contractAppendices));
    }

    /**
     * 删除合同附件
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractAppendices:remove')")
    @Log(title = "合同附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractAppendicesIds}")
    public AjaxResult remove(@PathVariable Long[] contractAppendicesIds)
    {
        return toAjax(contractAppendicesService.deleteContractAppendicesByContractAppendicesIds(contractAppendicesIds));
    }
}
